﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace KnowledgeCommunity.Service
{
    public static class WriteLog
    {
        public static void WriteSysLog(string sm)
        {
            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\\SysLog\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt"))
            {
                StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"\\SysLog\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt", true);
                sw.WriteLine("=======================================================================================");
                sw.WriteLine("Time:" + DateTime.Now.ToString("yyyyMMdd") + ": Message:" + sm);
                sw.WriteLine("=======================================================================================");
                sw.WriteLine("\r");
                sw.Close();
            }
            else
            {
                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"\\SysLog");
                StreamWriter sw2 = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"\\SysLog\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt", true);
                sw2.WriteLine("=======================================================================================");
                sw2.WriteLine("Time:" + DateTime.Now.ToString("yyyyMMdd") + ": Message:" + sm);
                sw2.WriteLine("=======================================================================================");
                sw2.WriteLine("\r\n");
                sw2.Close();
            }
        }
    }
}
